package dao

import (
	"errors"
	__ "order_srv/basic/orderproto"
	"order_srv/handler/models"
)

// 紧急求助
func EmergencyHelp(in *__.EmergencyHelpReq) (int64, error) {
	var e models.EmergencyHelp
	e.OrderId = in.OrderId
	e.UserId = in.UserId
	e.Location = in.Location
	e.Description = in.Description
	e.Status = "pending" // 默认状态为待处理
	if err := e.CreateEmergencyHelp(); err != nil {
		return 0, errors.New("紧急求助失败" + err.Error())
	}
	// 这里可以添加额外的逻辑，例如发送通知给客服或警方
	return int64(e.Id), nil
}

// 行程分享
func ShareTrip(in *__.ShareTripReq) (int64, error) {
	var s models.ShareTrip
	s.OrderId = in.OrderId
	s.UserId = in.UserId
	s.ShareTo = in.ShareTo
	s.ShareType = in.ShareType
	if err := s.CreateShareTrip(); err != nil {
		return 0, errors.New("创建分享记录失败" + err.Error())
	}

	// 这里可以添加实际的分享逻辑，例如发送短信、邮件或推送通知
	// 由于这只是示例，我们假设分享成功
	return int64(s.Id), nil
}

// 获取保险信息
func GetInsuranceInfo(in *__.GetInsuranceInfoReq) (*__.GetInsuranceInfoResp, error) {
	// 首先获取订单信息
	var order models.Orders
	err := order.GetOrderInfo(int(in.OrderId))
	if err != nil {
		return nil, errors.New("获取订单信息失败" + err.Error())
	}

	// 根据车型获取保险信息
	var insurance models.InsuranceInfo
	insuranceInfo, err := insurance.GetActiveInsuranceByCarType(order.CarTypeId)
	if err != nil {
		// 如果没有找到特定车型的保险信息，可以返回默认的保险信息
		return &__.GetInsuranceInfoResp{
			InsuranceCoverage:  "基础车辆保险和第三方责任险",
			TermsAndConditions: "详情请参考平台保险条款",
			ContactInfo:        "客服热线: 400-123-4567",
		}, nil
	}

	return &__.GetInsuranceInfoResp{
		InsuranceCoverage:  insuranceInfo.InsuranceCoverage,
		TermsAndConditions: insuranceInfo.TermsAndConditions,
		ContactInfo:        insuranceInfo.ContactInfo,
	}, nil
}
